﻿using System;
using System.Web;
using System.Web.UI;
using Cms.Application;
using Cms.Application.Admin.Views;
using Cms.Domain.Authentication;
using iLib.Web.UI;

namespace Cms.Web.Framework.Controls
{
    public class AdminPage : AdminBasePage, IAdminPageView
    {
        private AdminMaster _master;

        public virtual string HelpPage
        {
            get { return string.Empty; }
        }

        #region IAdminPageView Members

        public string UserPhysicalTempDirectory
        {
            get { return "Admin\\Resources\\Temp\\" + AdministratorID + "\\"; }
        }
        
        public string UserTempDirectory
        {
            get { return Url.FullPath + "Admin/Resources/Temp/" + AdministratorID + "/"; }
        }
        
        public string HeadingText
        {
            get { return _master.HeadingText; }
            set { _master.HeadingText = value; }
        }

        public virtual int AdministratorID
        {
            get
            {
                AuthenticatedUser user = Conversion.ToAuthenticatedUser(User.Identity.Name);
                return user.AdministratorID;
            }
        }

        #endregion

        public override void VerifyRenderingInServerForm(Control control)
        {
            return;
        }

        protected string GetText(ITranslatable view, string key)
        {
            return Translator.GetText(view.ContextTranslationFile, key, view.Localization);
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            _master = Master as AdminMaster;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.Now);
        }

        protected string HeadingIcon
        {
            get { return _master.HeadingIcon; }
            set { _master.HeadingIcon = value; }
        }
    }
}